"""
营销下的发送邮件页面类
"""
from ..base_page import BasePage
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

class SendEmailPage(BasePage):
    #数据
    url="/crm/index.php?m=setting&a=sendemail"
    #定位器
    email_locator = (By.LINK_TEXT, "发送邮件")
    addemail_locator = (By.CSS_SELECTOR,"body > div.container > div.row > div:nth-child(2) > form > div > div:nth-child(2) > p > a:nth-child(4)")

    emails_locator = (By.NAME, "emails")
    selectmail_locator = (By.NAME, "body > div.container > div.row > div:nth-child(2) > form > div > div:nth-child(2) > p > a:nth-child(2)")
    mailmodel_locator = (By.NAME, "template")
    mailtitle_locator = (By.NAME, "title")
    mailcontent_locator = (By.CSS_SELECTOR, "body")
    btn_locator = (By.CSS_SELECTOR,"body > div.container > div.row > div:nth-child(2) > form > div > div:nth-child(2) > div:nth-child(3) > input")
    #方法
    def click_email(self):
        self.click(self.email_locator)
    def addemail(self):
        self.click(self.addemail_locator)
    def emails(self,emails):
        self.send_keys(self.emails_locator,emails)
    def emailtitle(self,title):
        self.send_keys(self.mailtitle_locator,title)
    def mailmodel(self):
        mailmodel=self.find_element(self.mailmodel_locator)
        mailmodel_obj=Select(mailmodel)
        mailmodel_obj.select_by_visible_text("国庆快乐")

        WebDriverWait(self.driver, 10).until(
            EC.frame_to_be_available_and_switch_to_it(
                (By.CSS_SELECTOR, "iframe.ke-edit-iframe")
            )
        )
        self.driver.switch_to.default_content()
    def btn_save(self):
        self.click(self.btn_locator)

